package com.qiandao.xuexitong.controller;

import com.qiandao.xuexitong.common.Result;
import com.qiandao.xuexitong.dto.*;
import com.qiandao.xuexitong.service.AttendanceTaskService;
import com.qiandao.xuexitong.util.UserContext;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 学生端控制器
 */
@RestController
@RequestMapping("/api/student")
@RequiredArgsConstructor
public class StudentController {
    
    private final AttendanceTaskService attendanceTaskService;
    
    /**
     * 二维码签到
     */
    @PostMapping("/attendance/qrcode")
    public Result<Void> qrCodeSignIn(@Valid @RequestBody QrCodeSignInDTO dto) {
        // 获取当前学生ID
        Long studentId = UserContext.getUserId();
        
        // 执行签到
        attendanceTaskService.qrCodeSignIn(studentId, dto);
        
        return Result.success();
    }
    
    @PostMapping("/attendance/gesture")
    public Result<Void> gestureSignIn(@Valid @RequestBody GestureSignInDTO dto) {
        Long studentId = UserContext.getUserId();
        attendanceTaskService.gestureSignIn(studentId, dto);
        return Result.success();
    }
    
    @PostMapping("/attendance/location")
    public Result<Void> locationSignIn(@Valid @RequestBody LocationSignInDTO dto) {
        Long studentId = UserContext.getUserId();
        attendanceTaskService.locationSignIn(studentId, dto);
        return Result.success();
    }
    
    /**
     * 签到码签到
     */
    @PostMapping("/attendance/code")
    public Result<Void> codeSignIn(@Valid @RequestBody CodeSignInDTO dto) {
        Long studentId = UserContext.getUserId();
        attendanceTaskService.codeSignIn(studentId, dto);
        return Result.success();
    }
    
    /**
     * 一键签到
     */
    @PostMapping("/attendance/quick")
    public Result<Void> quickSignIn(@Valid @RequestBody QuickSignInDTO dto) {
        Long studentId = UserContext.getUserId();
        attendanceTaskService.quickSignIn(studentId, dto);
        return Result.success();
    }
    
    /**
     * 获取签到任务列表
     */
    @GetMapping("/attendance/tasks")
    public Result<List<StudentAttendanceTaskDTO>> getAttendanceTasks() {
        Long studentId = UserContext.getUserId();
        return Result.success(attendanceTaskService.getStudentAttendanceTasks(studentId));
    }
} 